package com.lagou.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lagou.dao.ProductsMapper;
import com.lagou.pojo.Products;
import com.lagou.pojo.ProductsVo;
import com.lagou.service.ProductsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author : liuchangling
 * @Descrition :
 * @Date： Created in 5:28 下午 2021/9/14
 */
@Service
public class ProductsServiceImp implements ProductsService {

    @Autowired
    private ProductsMapper productsMapper;

    @Override
    public Products findById(int id) {
        return productsMapper.selectById(id);
    }

    @Override
    public int deleteById(int id) {
        return productsMapper.deleteById(id);
    }

    @Override
    public int addProducts(Products products) {
        return productsMapper.insert(products);
    }

    @Override
    public int updateProducts(Products products) {
        return productsMapper.updateById(products);
    }

    @Override
    public Map<String, Object> selectPage(ProductsVo productsVo) {
        Map<String, Object> map = new HashMap<>();
        Page<Products> page = new Page<>(productsVo.getNum(), 10);
        QueryWrapper queryWrapper = new QueryWrapper<ProductsVo>();
        Page page1 = productsMapper.selectPage(page, queryWrapper);
        map.put("list", page1.getRecords());
        map.put("total", page1.getTotal());
        return map;
    }

    public List<Integer> selectMiddlePidsByOid(Integer id) {
        return productsMapper.selectMiddlePidsByOid(id);
    }

    @Override
    public List<Products> queryGoodsList(List<Integer> pIds)
    {
        List<Products> products = productsMapper.selectBatchIds(pIds);
        return products;
    }
}
